package com.base.engine.error;

import javax.swing.JOptionPane;

import org.lwjgl.opengl.Display;

import com.base.engine.MADEngine;
import com.base.engine.gui.MADUserInterface;

public final class MADErrorHandler {

	public static void throwException(EMADErrorCode code, Exception e){
		boolean fatal = EMADErrorCode.isFatalError(code);
		String fTitle = "" ;  
		String warning = "" ;
		if(fatal){
			fTitle = " - Fatal error!" ; 
			warning = "\nApplication will now be closed." ;
		}
		else fTitle = " - Runtime error!" ; 
		if(!(MADUserInterface.getDebuggingScreen() == null) && !fatal)
				MADUserInterface.getDebuggingScreen().addMessage(EMADErrorCode.getErrorMessageByCode(code), e.getMessage());
		else
			JOptionPane.showMessageDialog(null, EMADErrorCode.getErrorMessageByCode(code)+warning+"\n"+e.getClass(), 
											Display.getTitle()+fTitle, JOptionPane.OK_OPTION); 
		if(fatal)
			MADEngine.destroy();
	}
	
}
